package doc.ic.walkmore.weka;

import java.io.IOException;
import java.io.InputStream;

import weka.core.Instances;
import weka.core.converters.ArffLoader;

/**
 * 
 * play with ARFF File (http://weka.wikispaces.com/ARFF+%28book+version%29)
 * see trainingSet.arff
 * 
 * http://weka.wikispaces.com/Use+Weka+in+your+Java+code
 * 
 * @author paul
 *
 */
public class FileLoader {
	public static Instances getDataSetFromFile(InputStream arfffilename) throws IOException {
    	//System.out.println("\nOpening file "+arfffilename);
    	ArffLoader loader = new ArffLoader();
    	
		loader.setSource(arfffilename);
	    Instances data = loader.getDataSet();
		 // setting class attribute if the data format does not provide this information
		 // For example, the XRFF format saves the class attribute information as well
		 if (data.classIndex() == -1)
		   data.setClassIndex(data.numAttributes() - 1);
		 
		 return data;
	}
}

